package com.cjq.project.service.impl;

import com.cjq.common.domain.DTO.ProjectDTO;
import com.cjq.common.domain.Fee;
import com.cjq.common.domain.Project;
import com.cjq.common.domain.request.ProjectReq;
import com.cjq.common.domain.response.ProjectRes;
import com.cjq.common.result.PageResult;
import com.cjq.common.result.Result;
import com.cjq.project.mapper.ProjectMapper;
import com.cjq.project.service.ProjectService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProjectServiceImpl implements ProjectService {
    @Autowired
    private ProjectMapper projectMapper;
    @Autowired
    private StringRedisTemplate redisTemplate;

    @Override
    public Result<PageResult<ProjectRes>> projectList(ProjectReq projectReq) {
        PageHelper.startPage(projectReq.getPageNum(),projectReq.getPageSize());
        List<ProjectRes> projectResList = projectMapper.projectList(projectReq);
        PageInfo<ProjectRes> info = new PageInfo<>(projectResList);
        Result<PageResult<ProjectRes>> result = PageResult.toResult(info.getTotal(), projectResList);
        return result;
    }

    @Override
    public Result<List<Fee>> feeList() {
        List<Fee> feeList = projectMapper.feeList();
        return Result.success(feeList);
    }

    @Override
    public boolean insert(ProjectDTO projectDTO) {
        projectMapper.insert(projectDTO);
        return true;
    }
}
